package com.example.stuasist;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

import com.example.stuasist.db.stuasistDbOpenHelper;
import com.example.stuasist.db.dao.CourseDao;

public class information_edit extends Activity implements OnClickListener {
	
	private Button information_bt_return;
	private Button information_bt_sure;
	private EditText CNTextView;
	private EditText CTTextView;
	private EditText CRTextView;
	private EditText TerTextView;
	private EditText WeekTextView;

	String T_week_day;//周几的课
	int T_day_no;//第几节课
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);   //去掉标题栏
		super.setContentView(R.layout.information_edit);
		
		this.CNTextView =  (EditText) findViewById(R.id.information_edit_et_cname);
		this.CTTextView =  (EditText) findViewById(R.id.information_edit_et_ctime);
		this.CRTextView =  (EditText) findViewById(R.id.information_edit_et_croom);
		this.TerTextView =  (EditText) findViewById(R.id.information_edit_et_teacher);
		this.WeekTextView = (EditText) findViewById(R.id.information_edit_et_cweek);
		information_bt_return = (Button) findViewById(R.id.information_edit_bt_return);
		information_bt_sure = (Button) findViewById(R.id.information_edit_bt_sure);
		
		information_bt_return.setOnClickListener(this);
		information_bt_sure.setOnClickListener(this);
		
		Intent GetIntent = getIntent();
		String T_course_name = GetIntent.getStringExtra("T_to_info_edit_course_name");
		String T_time_detil = GetIntent.getStringExtra("T_to_info_edit_time_detil");
		String T_classroom = GetIntent.getStringExtra("T_to_info_edit_classroom");
		String T_teacher_name = GetIntent.getStringExtra("T_to_info_edit_teacher_name");
		String T_weeks =GetIntent.getStringExtra("T_to_info_edit_weeks");
		T_week_day =GetIntent.getStringExtra("T_to_info_edit_week_day");
		T_day_no = GetIntent.getIntExtra("T_to_info_edit_day_no", -1);
		
		CNTextView.setText(T_course_name);
		CTTextView.setText(T_time_detil);
		CRTextView.setText(T_classroom);
		TerTextView.setText(T_teacher_name);
		WeekTextView.setText(T_weeks);
		

		
		
		
	}

	@Override
	public void onClick(View v) {

		Intent intent;
		switch (v.getId()) {
		case R.id.information_edit_bt_return:
	
			intent = new Intent(information_edit.this,information.class);
			startActivity(intent);
			
			break;
		case R.id.information_edit_bt_sure:
			
			
			stuasistDbOpenHelper helper = new stuasistDbOpenHelper(this);
			
			helper.getReadableDatabase();
			
			CourseDao dao = new CourseDao(this);
			
			String course_name = CNTextView.getText().toString();
			String time_detil = CTTextView.getText().toString();
			String classroom = CRTextView.getText().toString();
			String teacher_name = TerTextView.getText().toString();
			String weeks = WeekTextView.getText().toString();
		
			
			dao.update(T_week_day, T_day_no, course_name, time_detil, classroom, teacher_name, weeks, T_week_day, T_day_no);
			
			intent = new Intent(information_edit.this,information.class);
			intent.putExtra("T_week_day", T_week_day);
			intent.putExtra("T_day_no", T_day_no);
			startActivity(intent);
			
			break;
		}
		
	}
	
	
	
	
}
